package com.xm.utils.common;

import org.bouncycastle.crypto.digests.SM3Digest;
import org.bouncycastle.util.encoders.Hex;

import java.nio.charset.StandardCharsets;

/**
 * SM3签名
 */
public class SM3Util {
    public static String sign(String str) {
        SM3Digest sm3Digest = new SM3Digest();
        byte[] message = str.getBytes(StandardCharsets.UTF_8);
        sm3Digest.update(message, 0, message.length);
        byte[] encrypt = new byte[sm3Digest.getDigestSize()];
        sm3Digest.doFinal(encrypt, 0);
        return Hex.toHexString(encrypt).toUpperCase();
    }
}